package com.changgou.business.listener;

import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class AdListener {

  @RabbitListener(queues = "item_queue")  //监听的队列
  public void myListener1(String message) {
    System.out.println("消费者接收到消息：" + message);


    //发起远程调用
    OkhttpClient okhttpClient = new OkhttpClient();
    String url = "http://192.168.200.128/ad_update?position=" + message;
    Request request = new Request.Builder().url(url).build();
    Call call = okHttpClient.newCall(request);

    call.enqueue(new Callback() {
      @Override
      public void onFailure(Call call, IOException e) {
        //请求失败
        e.printStackTrace();
      }

      @Override
      public void onResponse(Call call, Response response) throws
          IOException {
        //请求成功
        System.out.println("请求成功:" + response.message());
      }
    });
  }


}
